#include <iostream>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <strings.h>
#include <string.h>
#include <unistd.h>
#include <string>

// ./client 127.0.0.1 8080
int main(int argc, char* argv[])
{
    if (argc < 3) 
    {
        return 1;
    }

    std::string server_ip = argv[1];
    uint16_t server_port = std::stoi(argv[2]);

    int fd = socket(AF_INET, SOCK_STREAM, 0);
    struct sockaddr_in server_addr;
    bzero(&server_addr, sizeof server_addr);

    server_addr.sin_family = AF_INET;
    server_addr.sin_port = htons(server_port);
    server_addr.sin_addr.s_addr = inet_addr(server_ip.c_str());

    int n = connect(fd, (struct sockaddr*)&server_addr, sizeof(server_addr));
    if (n < 0);

    std::string buffer;
    std::getline(std::cin, buffer);

    send(fd, buffer.c_str(), buffer.size(), 0);

    close(fd);

    return 0;
}